package com.huajx.core.handler;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import com.huajx.core.model.HttpRequestMessage;
import com.huajx.core.model.HttpResponseMessage;

public class Invoke {
	private Class<? extends Controller> controller;
	private Method method;
	private HttpRequestMessage request;
	private HttpResponseMessage response;
	
	private String controllerKey;
	private String methodName;
	private String viewPath;
	
	public void invoke() throws InvocationTargetException, IllegalAccessException, InstantiationException {
		Controller o = controller.newInstance();
		
		o.setRequest(request);
		o.setControllerKey(controllerKey);
		o.setViewPath(viewPath);
		
		o.setResponse(response);
		
		method.invoke(o);
		
		if(!o.isRender()){
			o.render();
		}
    }
	
	public Class<? extends Controller> getController() {
		return controller;
	}
	
	public void setController(Class<? extends Controller> controller) {
		this.controller = controller;
	}
	public HttpRequestMessage getRequest() {
		return request;
	}
	public void setRequest(HttpRequestMessage request) {
		this.request = request;
	}

	public Method getMethod() {
		return method;
	}

	public void setMethod(Method method) {
		this.method = method;
	}

	public String getControllerKey() {
		return controllerKey;
	}

	public void setControllerKey(String controllerKey) {
		this.controllerKey = controllerKey;
	}

	public String getViewPath() {
		return viewPath;
	}

	public void setViewPath(String viewPath) {
		this.viewPath = viewPath;
	}

	public HttpResponseMessage getResponse() {
		return response;
	}

	public void setResponse(HttpResponseMessage response) {
		this.response = response;
	}

	public String getMethodName() {
		return methodName;
	}

	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}

}
